home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_exmh.idb / usr / freeware / lib / exmh-2.5 / pgpWWW.tcl.z / pgpWWW.tcl
Text File  |  2002-07-08  |  6KB  |  194 lines

  1. #
  2. # PGP functions to query for public keys via WWW
  3. # author: Carl Roth <roth@cse.ucsc.edu>
  4. #
  5. # query the keyserver:
  6. #
  7. #
  8. # Added keyfetching method hkp
  9. # -- Markus Gruber
  10. #
  11. # $Log: pgpWWW.tcl,v $
  12. # Revision 1.5  2000/06/16 23:41:37  jmorzins
  13. # Corrected the email address for the pgp.mit.edu email keyserver.
  14. #
  15. # Revision 1.4  2000/06/09 03:19:55  valdis
  16. # Provide known working default URL for PGP keys - www-swiss.ai.mit.edu wasnt working
  17. #
  18. # Revision 1.3  1999/08/22 18:17:08  bmah
  19. # Email PGP queries now go out correctly.  Use Exmh_Status to inform
  20. # user of state of an outgoing email key query.
  21. #
  22. # Revision 1.2  1999/08/03 04:05:56  bmah
  23. # Merge support for PGP2/PGP5/GPG from multipgp branch.
  24. #
  25. # Revision 1.1.4.1  1999/06/14 20:05:17  gruber
  26. # updated multipgp interface
  27. #
  28. # Revision 1.1  1999/06/14 15:14:55  markus
  29. # added files
  30. #
  31. # Revision 1.2  1998/12/24 12:59:09  markus
  32. # fixed variable path in WWW_QueryWWWKey
  33. #
  34. # Revision 1.1.1.1  1998/11/24 22:34:46  markus
  35. # Initial revision
  36. #
  37.  
  38. proc Pgp_WWW_Init {} {
  39. global pgp
  40.  
  41. # preferences
  42. set pgp(pref,keyserver) { keyserver KeyServer "pgp-public-keys@keys.pgp.net"
  43. {Favorite public key server}
  44. "When a signature check fails because of a missing key,
  45. exmh allows you to ask a key server for the key.
  46. Please select a key server that's close to
  47. you so as to spread the load.  Examples include
  48. pgp-public-keys@pgp.mit.edu
  49. pgp-public-keys@keys.pgp.net
  50. pgp-public-keys@keys.us.pgp.net
  51. There are pgp-public-keys@keys.*.pgp.net servers for these domains:
  52. ch de es fi kr nl no uk us pt se hr tw pl
  53. See also http://www.pgp.net/pgpnet/" }
  54. #
  55. set pgp(pref,keyserverUrl) { keyserverUrl KeyServerURL 
  56. {http://keys.pgp.com:11371/pks/lookup?op=get&exact=on&search=0x%s}
  57. {URL to fetch keys interactively}
  58. "The WWW keyserver is forms based.  Enter a URL here where
  59. the key id (sans 0x) is substituted with %s (using format)" }
  60. #
  61. set pgp(pref,keyquerymethod) { keyquerymethod KeyQueryMethod {CHOICE hkp WWW email other}
  62. {Method for querying <label> keys}
  63. "PGP public keys can be queried using email servers
  64. (offline), using WWW servers (interactive)
  65. or the Horowitz Key Protocol.
  66. A user-supplied proc (other) can also be given to fetch the key." }
  67. #
  68. set pgp(pref,keyothermethod) { keyothermethod KeyOtherMethod 
  69. {exec echo "can't find $id" > $tmp} 
  70. {Other method to fetch a <label> key}
  71. "The external method need to fetch the id in \$id and place
  72. it into the temp file \$tmp." }
  73.  
  74. }
  75.  
  76. proc Pgp_WWW_QueryKey { v id } {
  77.     global pgp
  78.  
  79.     # dispatch based on whether we use email or WWW:
  80.     if [info exists pgp($v,keyquerymethod)] {
  81.         switch [set pgp($v,keyquerymethod)] {
  82.             hkp { Pgp_WWW_QueryHKPKey $v $id }
  83.             WWW { Pgp_WWW_QueryWWWKey $v $id }
  84.             email { Pgp_WWW_QueryEmailKey $v $id }
  85. #            email { Pgp_Misc_Send [set pgp($v,keyserver)] "GET 0x$id" }
  86.             default { Pgp_WWW_QueryOtherKey $v $id }
  87.         }
  88.     } else {
  89.         Exmh_Status "No keyserver support for [set pgp($v,fullName)]"
  90.     }
  91. }
  92.  
  93. proc Pgp_WWW_QueryEmailKey { v id } {
  94.     global pgp
  95.  
  96.     Exmh_Debug "Pgp_WWW_QueryEmailKey $v $id"
  97.  
  98.     Exmh_Status "Sending query to get key $id from $pgp($v,keyserver)"
  99.     Pgp_Misc_Send [set pgp($v,keyserver)] "GET 0x$id"
  100.     Exmh_Status "Sent query to get key $id from $pgp($v,keyserver)"
  101. }
  102.  
  103. proc Pgp_WWW_QueryHKPKey { v id } {
  104.     global pgp
  105.  
  106.     Exmh_Debug "Pgp_WWW_QueryHKPKey $v $id"
  107.  
  108.     Exmh_Status "Running [set pgp($v,fullName)] to import key $id via HKP"
  109.     set server [set pgp($v,HKPkeyserverUrl)]
  110.     Pgp_Exec_Batch $v key [subst [set pgp($v,args_HKPimport)]] output
  111.     Exmh_Status "[lindex [split $output \n] end]"
  112.     Exmh_Debug "<Pgp_WWW_QueryHKPKey> $output"
  113. }
  114.  
  115. proc Pgp_WWW_make_msg {id file} {
  116.     global exmh
  117.  
  118.     set rcvstore [file dirname $exmh(slocal)]/rcvstore
  119.     set pipe [open "|$rcvstore +$exmh(folder)" w]
  120.     puts $pipe "Mime-Version: 1.0 (generated by exmh)"
  121.     puts $pipe "Content-Type: application/pgp; format=keys-only"
  122.     puts $pipe "Date: [exec date]"
  123.     puts $pipe "From: system"
  124.     puts $pipe "Subject: Output of pgp on id $id"
  125.     puts $pipe ""
  126.  
  127.     exec cat $file >@$pipe
  128.     close $pipe
  129.  
  130.     # update the folder listing:
  131.     Flist_FindUnseen
  132.     busy Scan_FolderForce
  133. }
  134.  
  135. proc Pgp_WWW_QueryStatus {state count length} {
  136.     if {$length} {
  137.     Exmh_Status [format "%s... %.1f%% complete" \
  138.              $state [expr 100.0 * $count / $length]]
  139.     } else {
  140.     Exmh_Status [format "%s..." $state]
  141.     }
  142. }
  143.  
  144. proc Pgp_WWW_QueryDone { v url file } {
  145.     global pgp
  146.  
  147.     upvar #0 $url data
  148.     if {[info exists data(html)]} {
  149.     set fd [open $file w]
  150.     puts -nonewline $fd $data(html)
  151.     close $fd
  152.     }
  153.     set pgp($v,querydone) 1
  154. }
  155.  
  156. proc Pgp_WWW_QueryWWWKey { v key } {
  157.     global pgp
  158.  
  159.     set url [format [set pgp($v,keyserverUrl)] $key]
  160.     set pgp($v,querydone) 0
  161.     Exmh_Status "posting query $url"
  162.  
  163.     set tmp [Mime_TempFile "pgpkey"]
  164.     Http_get $url "Pgp_WWW_QueryDone $v $url $tmp" Pgp_WWW_QueryStatus
  165.     tkwait variable pgp($v,querydone)
  166.     if {[file exists $tmp]} {
  167.     Exmh_Status "Saving key $key"
  168.     if [Pgp_Exec_ExtractKeys $v $tmp out 0] {
  169.         exec rm -f $tmp
  170.     }
  171.     } else {
  172.     Exmh_Status "unable to fetch key!"
  173.     }
  174. }
  175.  
  176. # query key using an external function
  177. proc Pgp_WWW_QueryOtherKey { v id } {
  178.     global pgp
  179.  
  180.     Exmh_Status "querying for key \[$id\]..."
  181.  
  182.     set tmp [Mime_TempFile "pgpkey"]
  183.     set cmd [eval [set pgp($v,keyothermethod)]]
  184.     if {[catch $cmd result]} {
  185.     Exmh_Status [format "unable to get key: %s" \
  186.              [lindex [split $key "\n"] 0]]
  187.     } else {
  188.     Exmh_Status "filing response"
  189.     Pgp_WWW_make_msg $id $tmp
  190.     }
  191.     exec rm -f $tmp
  192. }
  193.